home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1993 / Internet Info CD-ROM (Walnut Creek) (1993).iso / networking / ip / slip / sun / slip-4.1.shar < prev    next >
Encoding:
Text File  |  1992-01-06  |  22.5 KB  |  995 lines

  1. #! /bin/sh
  2. # This is a shell archive, meaning:
  3. # 1. Remove everything above the #! /bin/sh line.
  4. # 2. Save the resulting text in a file.
  5. # 3. Execute the file with /bin/sh (not csh) to create:
  6. # This archive created: Fri Jul  5 10:55:11 1991
  7.  
  8. export PATH; PATH=/bin:/usr/bin:$PATH
  9. #    slip-4.1/README
  10. #    slip-4.1/slip-attach.c
  11. #    slip-4.1/slip.h
  12. #    slip-4.1/slipencode.c
  13. #    slip-4.1/streamsip.c
  14. if test -f 'slip-4.1/README'
  15. then
  16.     echo shar: "will not over-write existing file 'slip-4.1/README'"
  17. else
  18. if test ! -d 'slip-4.1'
  19.     mkdir 'slip-4.1'
  20. fi
  21. sed -e s/X// << \SHAR_EOF > 'slip-4.1/README'
  22. XREADME for slip-4.1
  23. X
  24. XWorks for SunOS 4.1.1 20/12/1990
  25. XAdded congestion control 24/06/1991
  26. X
  27. Xcp slip.h /usr/include/sys
  28. Xcp slip.h /sys/sys
  29. Xcp streamsip.c slipencode.c /sys/os
  30. X
  31. Xedit /sys/conf.common/files.cmn
  32. X
  33. Xos/streamsip.c                optional slip
  34. Xos/slipencode.c               optional slip
  35. X
  36. X
  37. Xedit /sys/sun/str_conf.c
  38. X
  39. X#include "slip.h"
  40. X
  41. X#if     NSLIP > 0
  42. Xextern  struct  streamtab slipencode;
  43. Xextern  struct  streamtab streams_ip;
  44. X#endi
  45. X
  46. X#if     NSLIP > 0
  47. X    { "slipen", &slipencode },
  48. X    { "str_ip", &streams_ip },
  49. X#endif
  50. X
  51. X/sys/sun?/conf/MACHINE
  52. X
  53. Xpseudo-device    slip2
  54. X
  55. XBuild the new kernel, install and reboot.
  56. X
  57. Xcompile slip-attach
  58. X
  59. Xrun slip-attach
  60. X    slip-attach device speed local remote netmask
  61. Xe.g.
  62. X/usr/local/etc/slip-attach /dev/ttya 9600 192.42.62.1 192.42.62.2 255.255.255.0
  63. X
  64. XIf you wish to user this under 4.0 you will nedd to add the following
  65. Xdeclacation "char    mclrefcnt[];" to streamsip.c.
  66. X--
  67. XMark Andrews, CSIRO Div Maths & Stats, PO Box 218, Lindfield, NSW, Australia.
  68. XPHONE:  +61 2 413 7058          ACSNET: marka@dmssyd.dms.oz
  69. XARPA: marka@syd.dms.csiro.au    UUCP: ....!uunet!syd.dms.csiro.au!marka
  70. SHAR_EOF
  71. fi
  72. if test -f 'slip-4.1/slip-attach.c'
  73. then
  74.     echo shar: "will not over-write existing file 'slip-4.1/slip-attach.c'"
  75. else
  76. if test ! -d 'slip-4.1'
  77.     mkdir 'slip-4.1'
  78. fi
  79. sed -e s/X// << \SHAR_EOF > 'slip-4.1/slip-attach.c'
  80. X/*
  81. X *    slip-attach.c
  82. X *
  83. X *    Slip-attach opens and initalises the named device at the
  84. X *    requested speed, attaches the slip streams encodeing module and 
  85. X *    and streams IP network module and initaliases them. 
  86. X *
  87. X *    Copyright CSIRO Division of Mathematics and Statistics 21 June 1990
  88. X *
  89. X *    Portions of this code may be held by, Doug Kingston,Rayan Zachariassen,
  90. X *    and Greg Earle (see below).
  91. X *
  92. X *    Permission is hereby granted for this code to be distributed
  93. X *    free of charge with this copyright intact and does not interfere
  94. X *    with any copyrights held by the above. Derived works should
  95. X *    be marked as so.
  96. X */
  97. X
  98. X/*
  99. X * sliplogin.c
  100. X *
  101. X * This program initializes its own tty port to be an async TCP/IP interface.
  102. X * It merely sets up the SLIP module all by its lonesome on the STREAMS stack,
  103. X * initializes the network interface, and pauses forever waiting for hangup.
  104. X *
  105. X * It is a remote descendant of several similar programs with incestuous ties:
  106. X * - Kirk Smith's slipconf, modified by Richard Johnsson @ DEC WRL.
  107. X * - slattach, probably by Rick Adams but touched by countless hordes.
  108. X * - the original sliplogin for 4.2bsd, Doug Kingston the mover behind it.
  109. X * - a simple slattach-like program used to test the STREAMS SLIP code.
  110. X *
  111. X * Doug Kingston 8810??        - logging + first pass at adding I_STR ioctl's
  112. X * Rayan Zachariassen 881011    - version for SunOS STREAMS SLIP
  113. X * Greg Earle 890331        - added tip/UUCP style LCK lock file
  114. X */
  115. X
  116. X#include <sys/types.h>
  117. X#include <sys/socket.h>
  118. X#include <sys/stropts.h>
  119. X#include <sys/termios.h>
  120. X#include <sys/ttold.h>
  121. X#include <sys/sockio.h>
  122. X#include <sys/file.h>
  123. X#include <sys/syslog.h>
  124. X
  125. X#include <sys/slip.h>
  126. X
  127. X#include <netinet/in.h>
  128. X#include <net/if.h>
  129. X
  130. X#include <stdio.h>
  131. X#include <errno.h>
  132. X#include <ctype.h>
  133. X#include <netdb.h>
  134. X
  135. X#include <signal.h>
  136. X#include <strings.h>
  137. X#include <pwd.h>
  138. X#ifdef BSD >= 43
  139. X#include <ttyent.h>
  140. X#endif
  141. X
  142. Xvoid exit();
  143. X
  144. Xmain(argc, argv)
  145. X    int argc;
  146. X    char *argv[];
  147. X{
  148. X    int        fd, s, unit;
  149. X    int speed,i;
  150. X    int        sfd = 0;
  151. X    char    *device;
  152. X    char    *netmask;
  153. X    char    *localaddr;
  154. X    char    *dstaddr;
  155. X    struct termios    tios;
  156. X    struct ifreq    ifr;
  157. X    extern void    findid();
  158. X
  159. X    if (getuid() == 0) {
  160. X        if (argc != 6) {
  161. X            (void) fprintf(stderr,
  162. X                       "Usage: %s device speed localaddr destaddr netmask\n", argv[0]);
  163. X            exit(1);
  164. X        }
  165. X        device = argv[1];
  166. X        speed = atoi(argv[2]);
  167. X        localaddr = argv[3];
  168. X        dstaddr = argv[4];
  169. X        netmask = argv[5];
  170. X    } else
  171. X        exit(1);
  172. X
  173. X    switch (speed){
  174. X    case 50: speed = B50; break;
  175. X    case 75: speed = B75; break;
  176. X    case 110: speed = B110; break;
  177. X    case 134: speed = B134; break;
  178. X    case 150: speed = B150; break;
  179. X    case 200: speed = B200; break;
  180. X    case 300: speed = B300; break;
  181. X    case 600: speed = B600; break;
  182. X    case 1200: speed = B1200; break;
  183. X    case 1800: speed = B1800; break;
  184. X    case 2400: speed = B2400; break;
  185. X    case 4800: speed = B4800; break;
  186. X    case 9600: speed = B9600; break;
  187. X    case 19200: speed = B19200; break;
  188. X    case 38400: speed = B38400; break;
  189. X    default:
  190. X        (void)fprintf(stderr,"bad speed %d\n",speed);
  191. X        exit(1);
  192. X    }
  193. X
  194. X    for ( i = getdtablesize(); i--; )
  195. X        (void)close(i);
  196. X
  197. X    switch (fork()) {
  198. X    case    0:    /* child */
  199. X        break;
  200. X    default:
  201. X        exit(0);
  202. X        /* NOTREACHED */
  203. X    case    -1:    /* error */
  204. X        i = errno;
  205. X        openlog("slip-attach", LOG_PID|LOG_CONS, LOG_DAEMON);
  206. X        errno = i;
  207. X        syslog(LOG_ERR," fork() %m\n");
  208. X        exit(i);
  209. X        /* NOTREACHED */
  210. X    }
  211. X
  212. X    openlog("slip-attach", LOG_PID|LOG_CONS, LOG_DAEMON);
  213. X
  214. X    if ((fd = open("/dev/tty", O_RDONLY, 0)) >= 0) {
  215. X        (void) ioctl(fd, TIOCNOTTY, 0);
  216. X        (void) close(fd);
  217. X    }
  218. X
  219. X
  220. X    if (( sfd = open(device,O_RDWR,0)) < 0 ) {
  221. X        syslog(LOG_ERR, "open: %s: %m",device);
  222. X        exit(1);
  223. X    }
  224. X
  225. X    (void) fchmod(sfd, 0600);
  226. X
  227. X    /* pop all streams modules */
  228. X    while (ioctl(sfd, I_POP, 0) == 0)
  229. X        continue;
  230. X
  231. X    /* set up the line parameters */
  232. X    if (ioctl(sfd, TCGETS, (caddr_t)&tios) < 0) {
  233. X        syslog(LOG_ERR, "ioctl (TCGETS): %m");
  234. X        exit(1);
  235. X    }
  236. X    tios.c_cflag = CS8|CREAD|HUPCL|speed;
  237. X    tios.c_iflag = IGNBRK;
  238. X
  239. X    if (ioctl(sfd, TCSETS, (caddr_t)&tios) < 0) {
  240. X        syslog(LOG_ERR, "ioctl (TCSETS): %m");
  241. X        exit(1);
  242. X    }
  243. X
  244. X    /* push the SLIP module */
  245. X    if (ioctl(sfd, I_PUSH, "slipen") < 0) {
  246. X        syslog(LOG_ERR, "ioctl (I_PUSH) slipen: %m");
  247. X        exit(1);
  248. X    }
  249. X    if (ioctl(sfd, I_PUSH, "str_ip") < 0) {
  250. X        syslog(LOG_ERR, "ioctl (I_PUSH) str_ip: %m");
  251. X        exit(1);
  252. X    }
  253. X
  254. X    /* find out what unit number we were assigned */
  255. X    if (ioctl(sfd, SLIOGUNIT, (caddr_t)&unit) < 0) {
  256. X        syslog(LOG_ERR, "ioctl (SLIOGUNIT): %m");
  257. X        exit(1);
  258. X    }
  259. X
  260. X    syslog(LOG_NOTICE, "attaching stream%d: local %s remote %s mask %s\n",
  261. X        unit, localaddr, dstaddr, netmask);
  262. X
  263. X    /* set the local and remote interface addresses */
  264. X    s = socket(AF_INET, SOCK_DGRAM, 0);
  265. X
  266. X    (void) sprintf(ifr.ifr_name, "%s%d", "stream", unit);
  267. X    in_getaddr(netmask, &ifr.ifr_addr);
  268. X    if (ioctl(s, SIOCSIFNETMASK, (caddr_t)&ifr) < 0) {
  269. X        syslog(LOG_ERR, "ioctl (SIOCSIFNETMASK): %m");
  270. X        exit(1);
  271. X    }
  272. X
  273. X    (void) sprintf(ifr.ifr_name, "%s%d", "stream", unit);
  274. X    in_getaddr(dstaddr, &ifr.ifr_addr);
  275. X    if (ioctl(s, SIOCSIFDSTADDR, (caddr_t)&ifr) < 0) {
  276. X        syslog(LOG_ERR, "ioctl (SIOCSIFDSTADDR): %m");
  277. X        exit(1);
  278. X    }
  279. X
  280. X    (void) sprintf(ifr.ifr_name, "%s%d", "stream", unit);
  281. X    in_getaddr(localaddr, &ifr.ifr_addr);
  282. X    /* this has the side-effect of marking the interface up */
  283. X    if (ioctl(s, SIOCSIFADDR, (caddr_t)&ifr) < 0) {
  284. X        syslog(LOG_ERR, "ioctl (SIOCSIFADDR): %m");
  285. X        exit(1);
  286. X    }
  287. X    (void)pause();
  288. X    exit(0);
  289. X    /*NOTREACHED*/
  290. X}
  291. X
  292. X
  293. Xin_getaddr(s, saddr)
  294. X    char *s;
  295. X    struct sockaddr *saddr;
  296. X{
  297. X    register struct sockaddr_in *sin = (struct sockaddr_in *)saddr;
  298. X    struct hostent *hp;
  299. X    struct netent *np;
  300. X    u_long val;
  301. X    extern struct in_addr inet_makeaddr();
  302. X    extern u_long inet_addr();
  303. X    bzero((caddr_t)saddr, sizeof *saddr);
  304. X    sin->sin_family = AF_INET;
  305. X    val = inet_addr(s);
  306. X    if (val != (u_long)-1) {
  307. X        sin->sin_addr.s_addr = val;
  308. X        return;
  309. X    }
  310. X    hp = gethostbyname(s);
  311. X    if (hp) {
  312. X        sin->sin_family = hp->h_addrtype;
  313. X        bcopy(hp->h_addr, (char *)&sin->sin_addr, hp->h_length);
  314. X        return;
  315. X    }
  316. X    np = getnetbyname(s);
  317. X    if (np) {
  318. X        sin->sin_family = np->n_addrtype;
  319. X        sin->sin_addr = inet_makeaddr((int)np->n_net, (int)INADDR_ANY);
  320. X        return;
  321. X    }
  322. X    (void) fprintf(stderr, "slip_attach: %s: bad value\n", s);
  323. X    syslog(LOG_ERR, "%s: bad value\n", s);
  324. X    exit(1);
  325. X    /* NOTREACHED */
  326. X}
  327. SHAR_EOF
  328. fi
  329. if test -f 'slip-4.1/slip.h'
  330. then
  331.     echo shar: "will not over-write existing file 'slip-4.1/slip.h'"
  332. else
  333. if test ! -d 'slip-4.1'
  334.     mkdir 'slip-4.1'
  335. fi
  336. sed -e s/X// << \SHAR_EOF > 'slip-4.1/slip.h'
  337. X/*
  338. X * Header file for SunOS 4.0 streams SLIP module
  339. X *
  340. X * Copyright 1988 by Rayan Zachariassen
  341. X *
  342. X * You may do anything with this file except put your own
  343. X * copyright on it or change or remove this copyright notice.
  344. X */
  345. X
  346. X#ifndef    _sys_slip_h
  347. X#define    _sys_slip_h
  348. X
  349. X/*
  350. X * To compensate for lack of M_HANGUP on dialout lines, we use M_UNHANGUP
  351. X * as symptom of a possible carrier change, and generate a signal whenever
  352. X * an M_UNHANGUP passes by so the application can check for DCD.  This is
  353. X * a workaround that should go away when M_HANGUP is generated on dialouts.
  354. X */
  355. X
  356. X#include <sys/signal.h>
  357. X
  358. X/* signal to send application on stream device non-hangup DCD change */
  359. X#define    SIGDCD        SIGUSR1
  360. X
  361. X
  362. X#define    SLIPIFNAME    "slip"        /* base name of network interface */
  363. X
  364. X#define    SLIOGUNIT    _IOR(t, 62, int)        /* get SLIP unit no. */
  365. X#define    SLIOGSTATS    _IOR(t, 63, struct slipstat)    /* get statistics */
  366. X#define    SLIOSFLAGS    _IOW(t, 64, int)        /* set flags */
  367. X
  368. Xstruct slipstat {
  369. X    u_int        sl_ibytes;    /* total number of data bytes in */
  370. X    u_int        sl_ipackets;    /* total number of data packets in */
  371. X    u_int        sl_ierrors;    /* total number of input errors */
  372. X    u_int        sl_obytes;    /* total number of data bytes out */
  373. X    u_int        sl_opackets;    /* total number of data packets out */
  374. X    u_int        sl_oerrors;    /* total number of output errors */
  375. X};
  376. X
  377. X/* end of what the user-level process should care about */
  378. X
  379. X/* See RFC1055 for the origin of the following magic numbers */
  380. X
  381. X#define SLIPMTU        1006    /* this is the IP-level MTU */
  382. X
  383. X#define    END    0300        /* a frame just finished */
  384. X#define    ESC    0333        /* introduces an escape sequence */
  385. X#define    ESC_END    0334        /* the data contained an END */
  386. X#define    ESC_ESC    0335        /* the data contained an ESC */
  387. X
  388. X#endif    /* !_sys_slip_h */
  389. SHAR_EOF
  390. fi
  391. if test -f 'slip-4.1/slipencode.c'
  392. then
  393.     echo shar: "will not over-write existing file 'slip-4.1/slipencode.c'"
  394. else
  395. if test ! -d 'slip-4.1'
  396.     mkdir 'slip-4.1'
  397. fi
  398. sed -e s/X// << \SHAR_EOF > 'slip-4.1/slipencode.c'
  399. X/*
  400. X *    SLIP streams packet encoding/decoding module. SunOS 4.1.
  401. X *
  402. X *    Copyright CSIRO Division of Mathematics and Statistics 21 June 1990
  403. X *
  404. X *    Author: Mark Andrews, marka@syd.dms.csiro.au
  405. X *    
  406. X *    Tested Systems:
  407. X *        Sun 3/50 SunOS4.1 console ports.
  408. X *
  409. X *    The encoding/decoding algorithim is derived from work by
  410. X *    Rayan Zachariassen, rayan@ai.toronto.edu.
  411. X *
  412. X *      Permission is hereby granted for this code to be distributed
  413. X *      free of charge with this copyright intact. Derived works should
  414. X *      be marked as so.
  415. X
  416. X */
  417. X
  418. X#include <sys/types.h>
  419. X#include <sys/stream.h>
  420. X#include <sys/stropts.h>
  421. X#include <sys/param.h>
  422. X#include <sys/syslog.h>
  423. X
  424. X#include <sys/slip.h> /* from 4.0 slip code only needed for SLIPMTU */
  425. X
  426. X
  427. Xtypedef struct {
  428. X    int inlen;
  429. X    int sawescape;
  430. X    int overrun;
  431. X    unsigned char *dp;
  432. X    unsigned char buf[SLIPMTU];
  433. X    } slipb;
  434. X
  435. Xstatic int encode();
  436. Xstatic int decode();
  437. Xstatic int slopen();
  438. Xstatic int slclose();
  439. Xstatic int wput();
  440. X
  441. Xstatic struct module_info minfo = { 517, "slipen", 0, INFPSZ, 57600, 57600};
  442. X
  443. Xstatic struct qinit rinit = {
  444. X    decode, NULL, slopen, slclose, NULL, &minfo, NULL
  445. X    };
  446. Xstatic struct qinit winit = {
  447. X    wput, encode, NULL, NULL, NULL, &minfo, NULL
  448. X    };
  449. X
  450. Xstruct streamtab slipencode = { &rinit, &winit, NULL, NULL };
  451. X
  452. X
  453. Xstatic int slopen(q,dev,flag,sflag)
  454. X    queue_t *q;
  455. X    dev_t dev;
  456. X    int flag;
  457. X    int sflag;
  458. X{
  459. X    slipb *b;
  460. X    int s;
  461. X
  462. X    if((b = (slipb *)kmem_alloc(sizeof(slipb))) == NULL)
  463. X    return(OPENFAIL);
  464. X
  465. X    b->dp = b->buf;
  466. X    b->inlen = 0;
  467. X    b->overrun = 0;
  468. X    b->sawescape = 0;
  469. X
  470. X    s = splstr(s);
  471. X    OTHERQ(q)->q_ptr = q->q_ptr = (char *)b;
  472. X    splx(s);
  473. X
  474. X    return(0);
  475. X}
  476. X
  477. Xstatic int slclose(q,flag)
  478. X    queue_t *q;
  479. X    int flag;
  480. X{
  481. X    caddr_t p = q->q_ptr;
  482. X    int s;
  483. X
  484. X    s = splstr();
  485. X    OTHERQ(q)->q_ptr = q->q_ptr = 0;
  486. X    kmem_free(p,sizeof(slipb));
  487. X    splx(s);
  488. X}
  489. X
  490. Xstatic int wput(q,mp)
  491. X    queue_t *q;
  492. X    mblk_t *mp;
  493. X{
  494. X    switch (mp->b_datap->db_type) {
  495. X    case M_DATA:
  496. X    case M_FLUSH:
  497. X    putq(q,mp);
  498. X    break;
  499. X    default:
  500. X    putnext(q,mp);
  501. X    }
  502. X}
  503. X
  504. Xstatic int encode(q)
  505. X    queue_t *q;
  506. X{
  507. X    mblk_t *mp, *bp, *nb;
  508. X    int len;
  509. X    unsigned char *rp;
  510. X    unsigned char ch;
  511. X
  512. X
  513. X    while ((mp = getq(q)) != NULL) {
  514. X    switch (mp->b_datap->db_type) {
  515. X    default: /* paranoid */
  516. X        putnext(q,mp);
  517. X        continue;
  518. X    case M_FLUSH:
  519. X        if (*mp->b_rptr & FLUSHW)
  520. X        flushq(q, FLUSHDATA);
  521. X        putnext(q,mp);
  522. X        continue;
  523. X    case M_DATA:
  524. X        if(!canput(q->q_next)) {
  525. X        putbq(q,mp);
  526. X        return;
  527. X        }
  528. X        len = 2;
  529. X        for (bp = mp; bp != 0 ; bp = bp->b_cont ) {
  530. X        rp = bp->b_rptr;
  531. X        while (rp < bp->b_wptr) {
  532. X            ch = *rp++;
  533. X            len++;
  534. X            if ((ch == ESC) || (ch == END))
  535. X            len++;
  536. X        }
  537. X        }
  538. X        if ((nb = allocb(len,BPRI_MED)) == NULL) {
  539. X        log(LOG_DEBUG,"slipencode: unable to allocate write buffer\n");
  540. X           freemsg(mp);
  541. X           continue;
  542. X        }
  543. X        *nb->b_wptr++ = END;
  544. X        for (bp = mp; bp != 0 ; bp = bp->b_cont ) {
  545. X        rp = bp->b_rptr;
  546. X        while (rp < bp->b_wptr) {
  547. X            ch = *rp++;
  548. X            if (ch == END) {
  549. X            *nb->b_wptr++ = ESC;
  550. X            *nb->b_wptr++ = ESC_END;
  551. X            } else if ( ch == ESC ) {
  552. X            *nb->b_wptr++ = ESC;
  553. X            *nb->b_wptr++ = ESC_ESC;
  554. X            } else
  555. X            *nb->b_wptr++ = ch;
  556. X        }
  557. X        }
  558. X        *nb->b_wptr++ = END;
  559. X        putnext(q,nb);
  560. X        freemsg(mp);
  561. X    }
  562. X    }
  563. X}
  564. X
  565. Xstatic int decode(q,mp)
  566. X    queue_t *q;
  567. X    mblk_t *mp;
  568. X{
  569. X    slipb *b = (slipb *)q->q_ptr;
  570. X    mblk_t *bp, *nb;
  571. X    unsigned char *rp;
  572. X    unsigned char ch;
  573. X
  574. X    switch (mp->b_datap->db_type) {
  575. X    default:
  576. X    putnext(q,mp);
  577. X    break;
  578. X    case M_FLUSH:
  579. X    if (*mp->b_rptr & FLUSHR)
  580. X        flushq(q, FLUSHDATA);
  581. X    putnext(q,mp);
  582. X    break;
  583. X    case M_DATA:
  584. X    for (bp = mp; bp != 0 ; bp = bp->b_cont ) {
  585. X        rp = bp->b_rptr;
  586. X        while (rp < bp->b_wptr) {
  587. X        ch = *rp++;
  588. X        if (b->sawescape) { /* undo escape */
  589. X            b->sawescape = 0;
  590. X            if ( ch == ESC_END )
  591. X            ch = END;
  592. X            else if ( ch == ESC_ESC )
  593. X            ch = ESC;
  594. X        } else if (ch == END) { /* start/end character */
  595. X            if (b->overrun) { /* set up to recieve new packet */
  596. X            b->overrun = 0;
  597. X            b->inlen = 0;
  598. X            continue;
  599. X            }
  600. X            if (b->inlen == 0) /* start flag ignore */
  601. X            continue;
  602. X
  603. X            /* build new message */
  604. X            if ((nb = allocb(b->inlen,BPRI_MED)) == NULL) {
  605. X               log(LOG_DEBUG,"slipencode: unable to allocate read buffer dropping packet\n");
  606. X               b->inlen = 0;
  607. X               b->dp = b->buf;
  608. X               continue;
  609. X            }
  610. X            bcopy(b->buf, nb->b_wptr, b->inlen);
  611. X            nb->b_wptr += b->inlen;
  612. X            putnext(q,nb);
  613. X
  614. X            b->inlen = 0;    /* setup for next packet */
  615. X            b->dp = b->buf;
  616. X            continue;
  617. X
  618. X        } else if (ch == ESC) {
  619. X            b->sawescape = 1;
  620. X            continue;
  621. X        }
  622. X        if (++(b->inlen) > SLIPMTU) {
  623. X            if(!b->overrun)
  624. X            log(LOG_ERR,"slipencode: overrun\n");
  625. X            b->overrun = 1;
  626. X            b->dp = b->buf;
  627. X            continue;
  628. X        }
  629. X        *(b->dp)++ = ch;
  630. X        }
  631. X        bp->b_rptr = rp;
  632. X    }
  633. X    freemsg(mp);
  634. X    }
  635. X}
  636. SHAR_EOF
  637. fi
  638. if test -f 'slip-4.1/streamsip.c'
  639. then
  640.     echo shar: "will not over-write existing file 'slip-4.1/streamsip.c'"
  641. else
  642. if test ! -d 'slip-4.1'
  643.     mkdir 'slip-4.1'
  644. fi
  645. sed -e s/X// << \SHAR_EOF > 'slip-4.1/streamsip.c'
  646. X/*
  647. X *    Streams IP network module. SunOS 4.1.
  648. X *
  649. X *    Copyright CSIRO Division of Mathematics and Statistics 21 June 1990
  650. X *
  651. X *    Author: Mark Andrews, marka@syd.dms.csiro.au
  652. X *
  653. X *    Tested Systems:
  654. X *        Sun 3/50 SunOS4.1 console ports.
  655. X *
  656. X *    Permission is hereby granted for this code to be distributed
  657. X *    free of charge with this copyright intact. Derived works should
  658. X *    be marked as so.
  659. X */
  660. X
  661. X#include "slip.h"
  662. X#if NSLIP > 0
  663. X#include <sys/types.h>
  664. X#include <sys/stream.h>
  665. X#include <sys/stropts.h>
  666. X#include <sys/param.h>
  667. X#include <sys/systm.h>
  668. X#include <sys/user.h>
  669. X#include <sys/errno.h>
  670. X#include <sys/mbuf.h>
  671. X#include <sys/socket.h>
  672. X#include <sys/uio.h>
  673. X#include <sys/ioctl.h>
  674. X#include <sys/file.h>
  675. X#include <net/if.h>
  676. X#include <net/netisr.h>
  677. X#include <netinet/in.h>
  678. X#include <netinet/in_var.h>
  679. X#include <sys/syslog.h>
  680. X
  681. X#include <sys/slip.h> /* needed for SLIPMTU (should be derived from
  682. X    underlying streams module for PPP), and SLIOGUNIT */
  683. X
  684. X
  685. Xstatic int rput();
  686. Xstatic int wput();
  687. Xstatic int if_in();
  688. Xstatic int stream_open();
  689. Xstatic int stream_close();
  690. Xstatic int stream_ioctl();
  691. Xstatic int if_out();
  692. Xstatic int if_ioc();
  693. X
  694. Xstatic struct module_info minfo = { 518, "str_ip", 0, INFPSZ, 1024, 1024};
  695. X
  696. Xstatic struct qinit rinit = {
  697. X    rput, if_in, stream_open, stream_close, NULL, &minfo, NULL
  698. X    };
  699. Xstatic struct qinit winit = {
  700. X    wput, NULL, NULL, NULL, NULL, &minfo, NULL
  701. X    };
  702. X
  703. Xstruct streamtab streams_ip = { &rinit, &winit, NULL, NULL };
  704. X
  705. Xtypedef struct {
  706. X    queue_t *q;
  707. X    struct ifnet i
  708. X    } ifhead ;
  709. X
  710. Xstatic ifhead ifheads[NSLIP];
  711. X
  712. Xstatic int stream_open(q,dev,flag,sflag)
  713. X    queue_t *q;
  714. X    dev_t dev;
  715. X    int flag;
  716. X    int sflag;
  717. X{
  718. X    struct ifnet *ifp;
  719. X
  720. X    if(!suser()) {
  721. X    u.u_error = EPERM;
  722. X    return(OPENFAIL);
  723. X    }
  724. X
  725. X    for ( dev = 0 ; dev < NSLIP ; dev++)
  726. X    if ( !ifheads[dev].q )
  727. X        break;
  728. X
  729. X    if (dev > NSLIP)
  730. X    return(OPENFAIL);
  731. X
  732. X    ifp = &ifheads[dev].i;
  733. X    WR(q)->q_ptr = q->q_ptr = (caddr_t)&ifheads[dev];
  734. X    ifheads[dev].q = q;
  735. X
  736. X    if (!ifp->if_mtu) {
  737. X    ifp->if_name = "stream";
  738. X    ifp->if_mtu = SLIPMTU;
  739. X    ifp->if_flags = IFF_POINTOPOINT;
  740. X    ifp->if_unit = dev;
  741. X    ifp->if_ioctl = if_ioc;
  742. X    ifp->if_output = if_out;
  743. X    ifp->if_snd.ifq_maxlen = IFQ_MAXLEN;
  744. X
  745. X    if_attach(ifp);
  746. X    }
  747. X
  748. X    return(ifp->if_unit);
  749. X}
  750. X
  751. Xstatic int stream_close(q,flag)
  752. X    queue_t *q;
  753. X    int flag;
  754. X{
  755. X    ((ifhead *)(q->q_ptr))->q = NULL;
  756. X    ((ifhead *)(q->q_ptr))->i.if_flags &= ~IFF_UP;
  757. X    q->q_ptr = NULL;
  758. X}
  759. X
  760. Xstatic int wput(q,mp)
  761. X    queue_t *q;
  762. X    mblk_t *mp;
  763. X{
  764. X    struct iocblk *iocp;
  765. X
  766. X    switch (mp->b_datap->db_type) {
  767. X    case M_FLUSH:
  768. X    if (*mp->b_rptr & FLUSHW)
  769. X        flushq(q, FLUSHDATA);
  770. X    case M_IOCTL:
  771. X    iocp = (struct iocblk *) mp->b_rptr;
  772. X    switch(iocp->ioc_cmd) {
  773. X    case SLIOGUNIT:
  774. X        if ((mp->b_cont = allocb(sizeof(int),BPRI_MED)) == NULL) {
  775. X        mp->b_datap->db_type =  M_IOCNAK;
  776. X        iocp->ioc_error = ENOSR;
  777. X        } else {
  778. X        mp->b_datap->db_type = M_IOCACK;
  779. X        *((int *)(mp->b_cont->b_wptr)) = 
  780. X            ((ifhead *)(q->q_ptr))->i.if_unit;
  781. X        mp->b_cont->b_wptr += sizeof(int);
  782. X        iocp->ioc_count = sizeof(int);
  783. X        iocp->ioc_error = 0;
  784. X        }
  785. X        break;
  786. X    default:
  787. X        putnext(q,mp);
  788. X        return;
  789. X    }
  790. X    qreply(q,mp);
  791. X    break;
  792. X    default:
  793. X    putnext(q,mp);
  794. X    }
  795. X}
  796. X
  797. Xstatic int rput(q,mp)
  798. X    queue_t *q;
  799. X    mblk_t *mp;
  800. X{
  801. X    switch (mp->b_datap->db_type) {
  802. X    case M_DATA:
  803. X    case M_FLUSH:
  804. X    putq(q,mp);
  805. X    break;
  806. X    default:
  807. X    putnext(q,mp);
  808. X    }
  809. X}
  810. X
  811. Xstatic int if_out(ifp, m0, dst)
  812. X    struct ifnet *ifp;
  813. X    struct mbuf *m0;
  814. X    struct sockaddr *dst;
  815. X{
  816. X    int len = 0;
  817. X    queue_t *q = ifheads[ifp->if_unit].q;
  818. X    struct mbuf *m;
  819. X    mblk_t *mp;
  820. X    int s;
  821. X
  822. X    if (q == 0) {
  823. X    m_freem(m0);
  824. X    return(EHOSTDOWN);
  825. X    }
  826. X
  827. X    ifp->if_opackets++;
  828. X    switch (dst->sa_family) {
  829. X
  830. X    case AF_INET:
  831. X    for (m = m0; m!= 0 ; m = m->m_next) {
  832. X        len += m->m_len;
  833. X    }
  834. X    if ((mp = allocb(len, BPRI_MED)) == NULL) {
  835. X        ifp->if_oerrors++;
  836. X        m_freem(m0);
  837. X        return(ENOSR);
  838. X    }
  839. X    for (m = m0; m!= 0 ; m = m->m_next) {
  840. X        bcopy(mtod(m, u_char *),mp->b_wptr,m->m_len);
  841. X        mp->b_wptr += m->m_len;
  842. X    }
  843. X    s = splstr();
  844. X    if (q) {
  845. X        if (canput(WR(q)->q_next)) {
  846. X        putnext(WR(q),mp);
  847. X        } else {
  848. X        ifp->if_oerrors++;
  849. X        freemsg(mp);
  850. X        }
  851. X    } else
  852. X        freemsg(mp);
  853. X    splx(s);
  854. X    m_freem(m0);
  855. X    break;
  856. X    default:
  857. X    m_freem(m0);
  858. X    return(EAFNOSUPPORT);
  859. X    }
  860. X    return(0);
  861. X}
  862. X
  863. Xstatic int if_in(q)
  864. X    queue_t *q;
  865. X{
  866. X    mblk_t *mp, *bp;
  867. X    int len;
  868. X    struct mbuf *m;
  869. X    struct ifnet *ifp = &((ifhead*)q->q_ptr)->i;
  870. X    int offset;
  871. X    int s;
  872. X
  873. X
  874. X    while ((mp = getq(q)) != NULL) {
  875. X    switch (mp->b_datap->db_type) {
  876. X    default: /* paranoid */
  877. X        putnext(q,mp);
  878. X        continue;
  879. X    case M_FLUSH:
  880. X        if (*mp->b_rptr & FLUSHR)
  881. X        flushq(q, FLUSHDATA);
  882. X        putnext(q,mp);
  883. X        continue;
  884. X    case M_DATA:
  885. X        MGET(m, M_DONTWAIT, MT_DATA);    /* get an MBUF */
  886. X        if(!m) { /* dropit */
  887. X        ifp->if_ierrors++;
  888. X        freemsg(mp);
  889. X        log(LOG_ERR,"slip: MGET FAILED\n");
  890. X        continue;
  891. X        }
  892. X
  893. X        len = sizeof(ifp);
  894. X        for (bp = mp; bp != 0 ; bp = bp->b_cont ) {
  895. X        len += bp->b_wptr - bp->b_rptr;
  896. X        }
  897. X
  898. X        if (len > MLEN) {
  899. X        if (len > MCLBYTES) {
  900. X            ifp->if_ierrors++;
  901. X            freemsg(mp);
  902. X            m_freem(m);
  903. X            continue;
  904. X        }
  905. X        MCLGET(m);
  906. X        if (m->m_len == MLEN) {
  907. X            ifp->if_ierrors++;
  908. X            freemsg(mp);
  909. X            m_freem(m);
  910. X            log(LOG_ERR,"slip: MCLGET FAILED\n");
  911. X            continue;
  912. X        }
  913. X
  914. X        }
  915. X        /* assert mbuf big enough to hold whole message */
  916. X
  917. X        /* copy pointer */
  918. X        bcopy((char*)&ifp,mtod(m,char*),offset=sizeof(ifp));
  919. X
  920. X        /* copy data */
  921. X        for (bp = mp; bp != 0 ; bp = bp->b_cont ) {
  922. X        bcopy(bp->b_rptr,mtod(m,char*)+offset,bp->b_wptr - bp->b_rptr);
  923. X        offset += bp->b_wptr - bp->b_rptr;
  924. X        bp->b_rptr = bp->b_wptr;
  925. X        }
  926. X        m->m_len = offset;
  927. X
  928. X        ifp->if_ipackets++;
  929. X        /* enqueue / drop */
  930. X        s = splimp();
  931. X        if (IF_QFULL(&ipintrq)) {
  932. X        IF_DROP(&ipintrq);
  933. X        ifp->if_ierrors++;
  934. X        m_freem(m);
  935. X        (void) splx(s);
  936. X        log(LOG_ERR,"slip: IF_QFULL\n");
  937. X        } else {
  938. X        IF_ENQUEUE(&ipintrq, m);
  939. X        schednetisr(NETISR_IP);
  940. X        (void) splx(s);
  941. X        }
  942. X        freemsg(mp);
  943. X    }
  944. X    }
  945. X}
  946. X
  947. Xstatic int if_ioc(ifp, cmd, data)
  948. X    struct ifnet *ifp;
  949. X    int cmd;
  950. X    caddr_t data;
  951. X{
  952. X    struct ifaddr *ifa = (struct ifaddr *)data;
  953. X    int s;
  954. X    int error = 0;
  955. X
  956. X    if (ifa == NULL)
  957. X    return(EFAULT);
  958. X    s = splimp();
  959. X    switch (cmd) {
  960. X    case SIOCSIFADDR:
  961. X    switch (ifa->ifa_addr.sa_family) {
  962. X    case AF_INET:
  963. X        ifp->if_flags |= IFF_UP;
  964. X        break;
  965. X    default:
  966. X        error = EAFNOSUPPORT;
  967. X        break;
  968. X    }
  969. X    break;
  970. X    case SIOCSIFDSTADDR:
  971. X    switch (ifa->ifa_addr.sa_family) {
  972. X    case AF_INET:
  973. X        break;
  974. X    default:
  975. X        error = EAFNOSUPPORT;
  976. X        break;
  977. X    }
  978. X    break;
  979. X    default:
  980. X    error = EINVAL;
  981. X    }
  982. X    splx(s);
  983. X    return(error);
  984. X}
  985. X#endif
  986. SHAR_EOF
  987. fi
  988. exit 0
  989. #    End of shell archive
  990. - --
  991. Mark Andrews, CSIRO Div Maths & Stats, PO Box 218, Lindfield, NSW, Australia.
  992. PHONE:  +61 2 413 7058              ACSNET: marka@dmssyd.dms.oz
  993. INTERNET: marka@syd.dms.csiro.au    UUCP: ....!uunet!syd.dms.csiro.au!marka
  994.